using System;
using System.Text.RegularExpressions;

namespace RegexEditor
{
	/// <summary>
	/// Represents a portion of a string, analogous to a regex <see cref="Capture"/>.
	/// </summary>
	public class StringSegment
	{
		#region Public Members

		/// <summary>
		/// Gets or sets the position of the segment within the original string.
		/// </summary>
		public int Index { get; set; }

		/// <summary>
		/// Gets or sets the length of the segment.
		/// </summary>
		public int Length { get; set; }

		/// <summary>
		/// Gets or sets the segment string.
		/// </summary>
		public string Value { get; set; }

		/// <summary>
		/// Creates a segment from a regex capture.
		/// </summary>
		/// <param name="capture">The capture instance.</param>
		/// <returns>The segment instance.</returns>
		public static StringSegment FromCapture(Capture capture)
		{
			return new StringSegment { Index = capture.Index, Length = capture.Length, Value = capture.Value };
		}

		#endregion
	}
}
